package class202205.demo20.demo19.Heap;

import java.util.PrimitiveIterator;
import java.util.PriorityQueue;


class Card implements Comparable<Card> {
    public int rank; // 数值
    public String suit; // 花色

    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    public int compareTo(Card o) {
        //小堆
        //return this.rank - o.rank;
        //换大堆
        return  o.rank - this.rank;
    }

    @Override
    public String toString() {
        return "Card{" +
                "rank=" + rank +
                ", suit='" + suit + '\'' +
                '}';
    }
}
public class Test {

    public static void main2(String[] args) {
        //写了下面的代码 就已经有堆了
        PriorityQueue<Integer> primitiveIterator = new PriorityQueue<>();
        //验证大堆还是小堆   每放一个元素都得保证  是大堆 或者 小堆
        //这里默认小堆
        primitiveIterator.offer(12);
        primitiveIterator.offer(3);
        primitiveIterator.offer(15);
        //每次弹出去的 都是 小堆  或者大堆
        System.out.println(primitiveIterator.poll());
        System.out.println(primitiveIterator.poll());
    }

    public static void main3(String[] args) {
        int[] array = {27,15,19,18,28,34,65,49,25,37};
        TestHeap testHeap = new TestHeap();
        testHeap.createHeap(array);

        testHeap.heapShort();
        System.out.println("==========");

        /*testHeap.offer(80);
        System.out.println("==================");

        System.out.println(testHeap.poll());
        System.out.println(testHeap.poll());*/
    }

    public static void main(String[] args) {
        PriorityQueue<Card> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(new Card(2,"♥"));
        priorityQueue.offer(new Card(1,"♥"));

        System.out.println(priorityQueue);
        //primitiveIterator.offer(null);
    }

}
